package org.summerframework.component.security.core.event;

import org.summerframework.component.security.LoginData;
import lombok.Getter;
import lombok.Setter;
import org.springframework.context.ApplicationEvent;
import org.springframework.core.ResolvableType;
import org.springframework.core.ResolvableTypeProvider;

/**
 * @author 石超
 * @version v1.0.0
 */
@Getter
@Setter
public abstract class AbstractLoginEvent<T> extends ApplicationEvent implements ResolvableTypeProvider {
    private LoginData<T> loginData;

    public AbstractLoginEvent(LoginData<T> loginData) {
        super(loginData);
        this.loginData = loginData;
    }

    @Override
    public ResolvableType getResolvableType() {
        if (loginData.getUser() == null) {
            return ResolvableType.forClass(Object.class);
        } else {
            return ResolvableType.forClassWithGenerics(getClass(), ResolvableType.forInstance(loginData.getUser()));
        }
    }

}
